package password_rest_service::Model::password_rest_service;
#Hursk Insight
#Copyright (c) 2009 The Hursk Group, LLC. All rights reserved.
#
#www.hursk.com
#
#hurskgroup@hursk.com
#
#This software is distributed WITHOUT ANY WARRANTY; without even
#the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#PURPOSE.

use strict;
use base 'Catalyst::Model::DBIC::Schema';
use Config::IniFiles;
my $local_db_config_ini = 'local_db_config.ini';
my $db_config_ini = 'db_config.ini';
use Cwd;
if (-f $local_db_config_ini){ #set local equal to db_config_ini:
    $db_config_ini = $local_db_config_ini; 
}   elsif (-f $db_config_ini){
    #Nothing to do
}   else {
    die "Could not find local_db_config.ini or db_config.ini "
        ."in root application directory. "
        .cwd()." is the PWD and \$0 is $0\n";
}

my $cfg = new Config::IniFiles( -file => $db_config_ini );
my ($db_username, $db_password, $db_driver, $db_name, $db_hostname, $db_port);
if ( $cfg->val( 'database', 'username' ) ){
    $db_username = $cfg->val( 'database', 'username' );
    $db_username =~ s/^\s*|\s*$//g;
}   else {
    die "Database username not specified in db_config.ini file"
}
if ( $cfg->val( 'database', 'password' ) ){
    $db_password = $cfg->val( 'database', 'password' );
    $db_password =~ s/^\s*|\s*$//g;
}   else {
    die "Database password not specified in db_config.ini file"
}
if ( $cfg->val( 'database', 'driver' ) ){
    $db_driver = $cfg->val( 'database', 'driver' );
    $db_driver =~ s/^\s*|\s*$//g;
}   else {
    die "Database driver not specified in db_config.ini file"
}
if ( $cfg->val( 'database', 'name' ) ){
    $db_name = $cfg->val( 'database', 'name' );
    $db_name =~ s/^\s*|\s*$//g;
}   else {
    die "Database name not specified in db_config.ini file"
}
if ( $cfg->val( 'database', 'hostname' ) ){
    $db_hostname = $cfg->val( 'database', 'hostname' );
    $db_hostname =~ s/^\s*|\s*$//g;
}   else {
    die "Database hostname not specified in db_config.ini file"
}
if ( $cfg->val( 'database', 'port' ) ){
    $db_port = $cfg->val( 'database', 'port' );
    $db_port =~ s/^\s*|\s*$//g;
}   else {
    die "Database port not specified in db_config.ini file"
}

__PACKAGE__->config(
    schema_class => 'password_rest_service::Schema::password_rest_service',
    connect_info => [
            'dbi:'
            ."$db_driver:"#Database driver, followed by a colon
            ."$db_name:"#Database name, followed by a colon
            ."$db_hostname:"#Hostname, followed by a colon
            .$db_port,#Database port
            $db_username,#Username
            $db_password,#Password
        ],
);

=head1 NAME

password_rest_service::Model::password_rest_service - Catalyst DBIC Schema Model
=head1 SYNOPSIS

See L<password_rest_service>

=head1 DESCRIPTION

L<Catalyst::Model::DBIC::Schema> Model using schema L<password_rest_service::Schema::password_rest_service>

=head1 AUTHOR

Seth Viebrock

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
